<template>
	<yd-layout id='moneyDetail' class=''>
		
		<yd-infinitescroll v-show="transList.length>0" :callback="getTransaction" ref="infinitescrollDemo">
			
			<div  slot="list" class="list" v-for="item in transList">
				<div class="list_top">
					<div class="top_title c_size_34_48" >{{item.dtype==2?'直播打赏':item.dtype==3?'直播打赏':item.dtype==4?'提现':'充值'}}</div>
					<div class="top_money" :style="{color:item.trans_type==1?'#333333':'#333333'}">{{item.trans_type==1?'-':'+'}}{{item.coin}}</div>
				</div>
				<div class="time c_size_30_42">{{item.newTime}}</div>
			</div> 
			<!-- 数据全部加载完毕显示 -->
			<span slot="doneTip">没有更多数据了~~</span>

			<!-- 加载中提示，不指定，将显示默认加载中图标 -->
			<!--<img slot="loadingTip" src="path/img/loading.svg"/>-->
		</yd-infinitescroll>
		<NoList v-show='transList.length==0'>
			<img slot='img' src="../../assets/kong_2.png" alt="" />
		</NoList>
		 <yd-backtop></yd-backtop>
	</yd-layout>
</template>

<script>
	import { InfiniteScroll } from 'vue-ydui/dist/lib.rem/infinitescroll';
	import {BackTop} from 'vue-ydui/dist/lib.rem/backtop';
	export default{
		components:{
			[InfiniteScroll.name]: InfiniteScroll,
			[BackTop.name]: BackTop,
		},
		data(){
			return {
				pageNum: 1,
				pageCount: 10,
				transList: [],
			}
		},
		created() {
		},
		watch: {
			
		},
		computed: {
			
		},
		mounted(){
			//收入明细
			if(this.$route.query.type==1){
				document.title='消费明细'
			}else if(this.$route.query.type==2){
				document.title='收入明细'
			}else if(this.$route.query.type==3){
				document.title='提现明细'
			}else{
				document.title='充值明细'
			}
			this.getTransaction()
		},
		methods:{
			getTransaction(){
				this.$root.ajax({
					name: 'my/transaction',
					type:'get',
					params: {
						page: this.pageNum,
						count: this.pageCount,
						type:this.$route.query.type,
					}
				}).then((d) => {
					for(let a=0;a<d.data.trans_list.length;a++){
						d.data.trans_list[a].newTime = this.$root.getDate(new Date(d.data.trans_list[a].create_time*1000),{allTime:true})
						d.data.trans_list[a].coin = this.setMoneyZero(d.data.trans_list[a],'coin')
					}
					this.transList = [...this.transList, ...d.data.trans_list];
					if(this.transList.length >= d.data.trans_total) {
						/* 所有数据加载完毕 */
						this.$refs.infinitescrollDemo.$emit('ydui.infinitescroll.loadedDone');
						return;
					}

					/* 单次请求数据完毕 */
					this.$refs.infinitescrollDemo.$emit('ydui.infinitescroll.finishLoad');

					this.pageNum++;
				})
			},
			//处理金钱的0
			setMoneyZero(obj,str){
				if(obj[str]||obj[str]===0){
					if((obj[str]+'').indexOf('.')>=0){
						return obj[str]=obj[str].toFixed(1)
					}else{
						console.log(obj[str])
						return obj[str] = obj[str] + '.0'
					}
				}
			},
		}, 
		
	}
</script>

<style lang="scss">
	@import './moneyDetail.scss';
</style>